<?php
namespace huobi;

/**
 * 火币网接口
 */

class  Huobi{

	protected  $config;

	protected  $baseurl='https://api.huobi.pro/';

	function __construct($config=array()){
		$this->config = $config;
	}


	//获取所有交易对
	function  fetchSymbols(){
		$url = $this->baseurl.'v1/common/symbols';
		$rs =$this->curl_get($url);
		return $rs;
	}


	function  fetchTickers($markets=array()){
		if(empty($markets)){
			$url = $this->baseurl.'market/tickers';
		}else{
			$url = $this->baseurl.'market/detail/merged?symbol='.implode(',', $markets);
		}
		$rs =$this->curl_get($url);
		return $rs;
	}


	function curl_get($url,$timeout=300){
	    $ch = curl_init();                               
	    curl_setopt($ch, CURLOPT_URL, $url);            
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
	    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
	    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);   
	    $handles = curl_exec($ch);                         
	    $error = curl_error($ch);
	    if (!empty($error)) {
	        print_r($error);
	    }
	    curl_close($ch);  
	    return $handles; 
	}
}
?>